package cn.qh.com.controller;

import cn.qh.com.model.Person;
import cn.qh.com.service.imp.ServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;
import java.util.Optional;

/**
 * @project: crud
 * @description:
 * @author:
 * @date: 2021-08-17-11:37
 * @version: 1.0
 * @website:
 */
@RestController
public class PersonController {


    @Autowired
    private ServiceImp serviceImp;



    /**
     * 根据Id查询对象信息
     * @param id
     * @return
     */
    @RequestMapping("qubyId")
    public Person queryById(int id) {

        return serviceImp.queryById(id);
    }



    /**
     * 查询的对象所有信息
     * @param
     * @return
     */

    @RequestMapping("all")
    public List<Person> queryAll() {
        return serviceImp.queryAll();
    }



    /**
     * 获取对象信息保存到数据库中，插入
     * @param person
     * @return
     */
    @RequestMapping("insert")
    public String insert(Person person) {

        serviceImp.insert(person);
        return "success";
    }



    /**
     * 根据id删除对象信息
     * @param id
     * @return
     */
    @RequestMapping("delete")
    public int delete(int id) {
        return serviceImp.delete(id);
    }



    /**
     * 获取对象更新对象信息
     * @param person
     */
    @RequestMapping("update")
    public void update(Person person) {
        serviceImp.update(person);
    }
}
